package service;

import dao.OfficesDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.Offices;
import pojo.OfficesPage;

import java.util.List;

/**
 * @author 李主席
 * @create 2020-12-09 9:07
 */
@Service
public class OfficesServiceImpl implements OfficesService {

    @Autowired
    private OfficesDao officesdao;

    @Override
    public OfficesPage getAllUsers(Integer page, Integer size) {
        Integer start = (page - 1) * size;
        List<Offices> offices = officesdao.selectAllUsers(start, size);
        Integer count = officesdao.selectofficesCount();
        Integer pageCount = count % size == 0 ? count / size : count / size + 1;
        OfficesPage officesPage = new OfficesPage();
        officesPage.setPageCount(pageCount);
        officesPage.setOfficesList(offices);
        officesPage.setPageSize(size);
        officesPage.setRowCount(count);
        officesPage.setPageNum(page);

        return officesPage;
    }

    @Override
    public Integer addOneOffice(Offices offices)     {
        return officesdao.insertOneOffice(offices);
    }
}
